from  cn.dbswitcher.DatabaseSource import *


def testSqlServerConn():
    conn = getSqlServerConn("201")
    cur = conn.cursor()
    if not cur:
        raise (NameError, "连接数据库失败")
    else:
        cur.execute("select * from Area")
        data = cur.fetchall()
        for ret in data:
            print(str(ret[0]) + "-->" + str(ret[1]) + "\n")
        conn.close()


if __name__ == '__main__':
    testSqlServerConn()


def mssql2mysql(msConn, myConn, mssql, mysql):
    msCur = msConn.cursor()
    data = tuple
    counter = 0
    if not msCur:
        raise (ConnectionError, "Mssql数据链接出错")
    else:
        msCur.execute(mssql)
        data = msCur.fetchall()
        msConn.close()
    myCur = myConn.cursor()
    if not myCur:
        raise (ConnectionError, "Mysql数据链接出错")
    else:
        for ret in data:
            counter += 1
            myCur.execute(mysql, ret)
        myConn.commit()
        myCur.close()
        myConn.close()
    print("总共导入数据" + str(counter) + "条")
